exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
  /**
   * 自定义表单保存
   *
   * @returns
   */
  saveCustFormAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      let aj = think.ajaxJson();
      let postData = _this.post("create_by,create_date,form_items,id,template_code,template_name,update_by,update_date,form_type,icon_path");
      const CusFormService = _this.service("oa/CusFormService");
      const res = yield CusFormService.saveCustForm(postData);
      console.log("Res:", res);
      if (!res) {
        aj.success = false;
        aj.msg = "审批编码重复,请从新输入";
      }
      if (res && res.error) {
        aj.success = false;
        aj.msg = "表单添加错误";
      }
      return _this.json(aj);
    })();
  }
  /**
   * 获取表单图标
   *
   * @returns
   */
  getCusFormIconAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      let aj = think.ajaxJson();
      const CusFormService = _this2.service("oa/CusFormService");
      const res = yield CusFormService.getCusFormIcon();

      if (res && res.error) {
        aj.success = false;
        aj.msg = "获取失败";
      } else {
        aj.result = res;
      }
      return _this2.json(aj);
    })();
  }
  /**
   * 获取首页展示模板简单列表（全部）
   *
   * @returns
   */
  getCusFormSimpleInfoByAllAction() {
    var _this3 = this;

    return _asyncToGenerator(function* () {
      let aj = think.ajaxJson();
      const CusFormService = _this3.service("oa/CusFormService");
      const res = yield CusFormService.getCusFormSimpleInfoByAll();
      if (res && res.error) {
        aj.success = false;
        aj.msg = "获取失败";
      } else {
        aj.result = res;
      }
      return _this3.json(aj);
    })();
  }
  /**
   * 获取所有表单信息
   *
   * @returns
   */
  getCusFormInfoByAllAction() {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      let aj = think.ajaxJson();
      const CusFormService = _this4.service("oa/CusFormService");
      const res = yield CusFormService.getCusFormInfo();
      if (res && res.error) {
        aj.success = false;
        aj.msg = "获取失败";
      } else {
        aj.result = res;
      }
      return _this4.json(aj);
    })();
  }
  /**
   * 通过Id获取表单模板信息
   *
   * @returns
   */
  getCusFormInfoByIdAction() {
    var _this5 = this;

    return _asyncToGenerator(function* () {
      let aj = think.ajaxJson();
      const CusFormService = _this5.service("oa/CusFormService");
      let PostData = {
        id: _this5.post("id")
      };
      const res = yield CusFormService.getCusFormInfoById(PostData);
      if (res && res.error) {
        aj.success = false;
        aj.msg = "获取失败";
      } else {
        aj.result = res;
      }
      return _this5.json(aj);
    })();
  }
};